package com.doit.day01;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.TableName;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Table;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;

public class _01_put数据 {
    public static void main(String[] args) throws Exception {
        Configuration conf = HBaseConfiguration.create();
        conf.set("hbase.zookeeper.quorum","linux01:2181");

        Connection conn = ConnectionFactory.createConnection(conf);

        Table table = conn.getTable(TableName.valueOf("doit:abc"));

        //需要一个put对象，给你一个就完事了
        Put put = new Put("rowkey001".getBytes(StandardCharsets.UTF_8));
        put.addColumn("f2".getBytes(), "name".getBytes(), "zss".getBytes());
        put.addColumn("f2".getBytes(), "age".getBytes(), "18".getBytes());
        put.addColumn("f3".getBytes(), "gender".getBytes(), "male".getBytes());
        put.addColumn("f3".getBytes(), "address".getBytes(), "shanghai".getBytes());
        put.addColumn("f4".getBytes(), "phone".getBytes(), "110".getBytes());
        put.addColumn("f4".getBytes(), "id".getBytes(), "1".getBytes());

        Put put11 = new Put("rowkey002".getBytes(StandardCharsets.UTF_8));
        put11.addColumn("f2".getBytes(), "name".getBytes(), "zss".getBytes());
        put11.addColumn("f2".getBytes(), "age".getBytes(), "18".getBytes());
        put11.addColumn("f3".getBytes(), "gender".getBytes(), "male".getBytes());
        put11.addColumn("f3".getBytes(), "address".getBytes(), "shanghai".getBytes());
        put11.addColumn("f4".getBytes(), "phone".getBytes(), "110".getBytes());
        put11.addColumn("f4".getBytes(), "id".getBytes(), "1".getBytes());

        //创建一个集合，将所有的put对象都放在集合中
        ArrayList<Put> puts = new ArrayList<>();
        puts.add(put);
        puts.add(put11);

        //将集合添加到表里面去
        table.put(puts);


    }
}
